﻿@model SportsStore.Domain.Entities.Product
@{
    ViewBag.Title = "Admin: Edit"+Model.Name;
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
    //不希望 使用客戶端驗證
 HtmlHelper.ClientValidationEnabled = false;
    HtmlHelper.UnobtrusiveJavaScriptEnabled = false;
}
<div class="panel">
    <div class="panel-heading">
        <h3>Edit @Model.Name</h3>
    </div>
    @using (Html.BeginForm("Edit","Admin",FormMethod.Post,new { enctype="multipart/form-data"}))
    {
        <div class="panel-body">
            @Html.HiddenFor(m => m.ProductID)
            @foreach (var property in ViewData.ModelMetadata.Properties)
            {
                switch (property.PropertyName)
                {
                    case "ProductID":
                    case "ImageData":
                    case "ImageMimeType":
                        break;
                    default:
                            <div class="form-group">
                                <label>@(property.DisplayName ?? property.PropertyName)</label>
                                @if (property.PropertyName == "Description")
                                {
                                    @Html.TextArea(property.PropertyName, null, new { @class = "form-control", rows = 5 })
                                }
                                else
                                {
                                    @Html.TextBox(property.PropertyName, null, new { @class = "form-control" })
                                }
                                @Html.ValidationMessage(property.PropertyName)
                            </div>break;
                    }
                }
                <div class="form-group">
                    <div style="position:relative;">
                        <label>Image</label>
                        <a class="btn" href="javascript:;">
                            Choose File...
                            <input type="file" name="Image" size="40" style="position:absolute;
                                        z-index:2;top:0;left:0;filter:alpha(opacity=0);opacity:0;
                                    background-color:transparent;color:transparent; " 
                                     onchange='$("#upload-file-info").html($(this).val());'/>
                        </a>
                        <span class="label label-info" id="upload-file-info"></span>
                    </div>
                    @if (Model.ImageData == null)
                    {
                        <div class="form-control-static">No Image</div>
                    }
                    else
                    {
                        <img class="img-thumbnail" width="150" height="150" 
                             src="@Url.Action("GetImage","Product",new { Model.ProductID})"/>
                    }
                </div>        
        </div>
        <div class="panel-footer">
            <input type="submit" value="Save" class="btn btn-primary" />
            @Html.ActionLink("Cancel and return to List", "Index", null, new { @class = "btn btn-default" })
        </div>
    }  
</div>


